<?php

// +----------------------------------------------------------------------
// | 微信支付 api控制器
// +----------------------------------------------------------------------
// | @author fancsen
// +----------------------------------------------------------------------

/**
 * 微信支付 api控制器
 * @author fancsen
 */


namespace app\api\controller\v1;

use app\api\controller\BaseController;
use app\api\validate\IDMustBePostiveInt;
use app\api\service\Pay as PayService;
use app\api\service\WxNotify as WxNotifyService;

class Pay extends BaseController
{   
    

    //前置成员变量
    protected $beforeActionList = [
        'checkExclusiveScope' => ['only' => 'getPreOrder'] 
    ];

    /**
     * 调用微信支付
     * @param int 订单id
     */
    public function getPreOrder($id = null)
    {
        (new IDMustBePostiveInt())->goCheck();

        $payService = new PayService($id);
        
        return $payService->pay();
    }
    /**
     * 微信回调接口
     */
    public function receiveNotify()
    {
        //回调通知频率为15/15/30/180/1800/1800/1800/3600,单位:秒
        
        //1,检查库存
        //2，更新订单状态
        //3，减库存
        //处理成功，给微信返回成功处理信息，失败返回失败处理信息，微信重新请求
        $wxNotify = new WxNotifyService();
        $wxNotify->Handle();
    }
}